package org.lee.res;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.util.Locale;

/**
 * ResRunner
 *
 * @author dralee
 * @date 2021-12-28 16:16:07
 **/
@Component
public class ResRunner implements CommandLineRunner {

    @Autowired
    private MessageSource messageSource;

    @Override
    public void run(String... args) throws Exception {
        String[] keys = {"earth", "ocean"};
        for (String key : keys) {
            System.out.printf("key: %s\r\n", key);
            output(key);
            System.out.println();
        }
    }

    private void output(String key) {
        Locale[] locales = {new Locale("sk", "SK"), Locale.FRANCE, Locale.GERMAN, Locale.ENGLISH, Locale.JAPAN, Locale.KOREA, Locale.CHINA};
        for (Locale locale : locales) {
            System.out.println(new String(messageSource.getMessage(key, null, locale).getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
        }
    }
}
